<?php

namespace mpend\modules\assist\models;

use Yii;
use common\helpers\ArrayHelper;
use common\logics\PositionLogic;
use common\models\feedback\Feedback;
use common\models\help\Help;
use common\models\help\HelpCategory;
use common\helpers\Url;

/**
 * 客服中心首页信息
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class AssistDashboardLogic extends \common\logics\DashboardLogic {

    /**
     * @var array 用户信息
     */
    public $user = null;

    /**
     * @var array 热议问题
     */
    public $heateds = [];

    /**
     * @var array 问题分类（含推荐内容）
     */
    public $categorys = [];

    /**
     * @var array 意见反馈
     */
    public $feedback = [];

    /**
     * 用户信息
     *
     * @inheritdoc
     */
    protected function setUser() {
        $user = Yii::$app->user->identity;
        if ($user) {
            return $user->meta;
        }
        return null;
    }

    /**
     * 热议问题
     *
     * @inheritdoc
     * @throws \yii\base\InvalidConfigException
     */
    protected function setHeateds() {
        return Help::find()->active()->orderBy([
            'listorder' => SORT_DESC,
            'views' => SORT_DESC,
        ])->limit(3)->orderBy('rand()')->all();
    }

    /**
     * 问题分类
     *
     * @inheritdoc
     * @throws \yii\base\InvalidConfigException
     */
    protected function setCategorys() {
        return HelpCategory::find()->active(HelpCategory::STATUS_ACTIVE)->orderBy([
            'listorder' => SORT_ASC
        ])->all();
    }

    /**
     * 意见反馈
     *
     * @inheritdoc
     */
    protected function setFeedback() {
        return Url::weblink('feedback');
    }

}
